home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 18 / AMIGAplus Sonderheft 18 (1999)(ICP)(DE)[!].iso / PD / Anwendungen / ppclibemu / tests / objattr_demo.c < prev    next >
C/C++ Source or Header  |  1999-01-03  |  2KB  |  63 lines

  1. /*
  2.  * Shows all symbols of an ELF object by using PPCGetObjectAttrs()
  3.  *
  4.  * __reg("xx") is vbcc-specific. If you use another compiler you
  5.  * will have to change it.
  6.  */
  7.  
  8. #include <exec/libraries.h>
  9. #include <utility/tagitem.h>
  10. #include <powerup/ppclib/object.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <proto/ppc.h>
  14.  
  15. struct Library *PPCLibBase;
  16.  
  17.  
  18. static void ScanHookFunc(__reg("a0")struct Hook *MyHook,
  19.                          __reg("a2")void *MyElfStruct,
  20.                          __reg("a1")struct PPCObjectInfo *MyInfo)
  21. {
  22.   Printf("0x%08lx\t0x%08lx\t%s\n",
  23.          MyInfo->Address,
  24.          MyInfo->Size,
  25.          MyInfo->Name);
  26. }
  27.  
  28.  
  29. main(int argc,char *argv[])
  30. {
  31.   if (argc != 2) {
  32.     Printf("Usage: %s <elf-object>\n",argv[0]);
  33.     exit(1);
  34.   }
  35.  
  36.   if (PPCLibBase = OpenLibrary("ppc.library",46)) {
  37.     void *eo;
  38.  
  39.     if (eo = PPCLoadObject(argv[1])) {
  40.       struct PPCObjectInfo MyInfo;
  41.       struct TagItem MyTags[2];
  42.       struct Hook MyScanSymbolHook;
  43.  
  44.       MyScanSymbolHook.h_Entry = (ULONG (*)(void)) ScanHookFunc;
  45.       MyScanSymbolHook.h_SubEntry = (ULONG (*)(void)) NULL;
  46.       MyScanSymbolHook.h_Data = (APTR) PPCLibBase;
  47.       MyTags[0].ti_Tag = PPCELFINFOTAG_SCANSYMBOLHOOK;
  48.       MyTags[0].ti_Data = (ULONG)&MyScanSymbolHook;
  49.       MyTags[1].ti_Tag = TAG_END;
  50.       PPCGetObjectAttrs(eo,&MyInfo,MyTags);
  51.       PPCUnLoadObject(eo);
  52.     }
  53.     else
  54.       Printf("Can't load ELF object %s\n",argv[1]);
  55.     CloseLibrary(PPCLibBase);
  56.   }
  57.   else {
  58.     Printf("Can't open ppc.library V46!\n");
  59.     exit(1);
  60.   }
  61.   exit(0);
  62. }
  63.